#include"compile_run.hpp"
#include"../comm/httplib.h"
#include "../comm/spdlog.hpp"

DEFINE_string(ip, "127.0.0.1", "这是服务器的监听IP地址，格式：127.0.0.1");
DEFINE_int32(port, 8080, "这是服务器的监听端口, 格式: 8080");

using namespace y_compile_and_run;
using namespace httplib;

int main(int argc, char *argv[])
{
    //初始化日志
    google::ParseCommandLineFlags(&argc, &argv, true);
    init_logger(FLAGS_run_mode,FLAGS_log_file,FLAGS_log_level);

    Server svr;

    //Postq请求发送JSON数据
    svr.Post("/compile_and_run",[](const Request& req,Response& resp)
    {
        //用户请求的服务正文是我们想要的json string
        std::string in_json=req.body;
        std::string out_json;
        if(!in_json.empty())
        {
            CompileAndRun::Start(in_json,&out_json);
            resp.set_content(out_json,"application/json;charset=utf-8");
        }
    });
    svr.listen("0.0.0.0",FLAGS_port);
    return 0;
}